package com.example.criminalintent.activity;

import com.example.criminalintent.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

public abstract class SingleFragmentActivity extends FragmentActivity {
	
	protected abstract Fragment createFragment();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fragment);
		
		// call the FragmentManager itself
		FragmentManager fm = getSupportFragmentManager();
		Fragment mFragment = fm.findFragmentById(R.id.fragment_container);
		
		if (mFragment == null) {
			mFragment = createFragment();
			fm.beginTransaction().add(R.id.fragment_container, mFragment).commit();
		}
	}
}
